// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
#include "pch.h"
#include "TemperatureToColorConverter.h"
#include "UserSettings.h"

using namespace Weathr;
using namespace Platform;
using namespace Windows::UI;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;

Object^ TemperatureToColorConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
    (void) targetType; // Unused parameter
    (void) parameter;  // Unused parameter
    (void) language;   // Unused parameter

    static SolidColorBrush^ coolBrush = ref new SolidColorBrush(Colors::LightSkyBlue);
    static SolidColorBrush^ warmBrush = ref new SolidColorBrush(Colors::Red);

    auto boxedInt32 = dynamic_cast<Box<int32>^>(value);
    if (boxedInt32 == nullptr)
    {
        // Not expected.
        assert(false);
        return ref new SolidColorBrush(Colors::White);
    }

    const int32 temperature = boxedInt32->Value;
    return temperature <= (UserSettings::Current->IsCelsiusSet ? 0 : 32) ? coolBrush : warmBrush;
}

Object^ TemperatureToColorConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
    (void) value;      // Unused parameter
    (void) targetType; // Unused parameter
    (void) parameter;  // Unused parameter
    (void) language;   // Unused parameter
    throw ref new NotImplementedException();
}